#include "battle.h"
//防御检定
void Def_Check(int choose, herodata hero)
{
	if (hero.Stun == 0)
	{
		if (choose == 4)
		{
			printf("%s进行了防御,抵挡本次伤害\n", hero.name);
		}
	}
}

//攻击检定
herodata Attack_Check(int choose1, int choose2, herodata hero1, herodata hero2,int action)
{
	if (hero2.Stun != 0)
	{
		hero2.Stun++;
	}
	if (action==0 && hero1.HP>0 && hero2.HP>0)
	{
		if (hero1.Stun == 0) {
			if (choose2 > choose1 || hero2.Stun != 0)
			{
				if (choose1!=4)
				{
					printf("'%s'进行了攻击\n", hero1.name);
				}
				if (choose2 != 4)
				{
					if (choose1 == 1)
					{
						printf("'%s'轻攻击,对'%s'造成了'%d'点伤害\n", hero1.name, hero2.name, hero1.POW / 2 - hero2.DEF);
						hero2.HP -= (hero1.POW / 2 - hero2.DEF);
						printf("'%s'剩余'%d'HP\n", hero2.name, hero2.HP);
					}
					if (choose1 == 2)
					{
						printf("'%s'中攻击,对'%s'造成了'%d'点伤害\n", hero1.name, hero2.name, hero1.POW - hero2.DEF);
						hero2.HP -= (hero1.POW - hero2.DEF);
						printf("'%s'剩余'%d'HP\n", hero2.name, hero2.HP);
						hero2.Stun += 3;
					}
				}
				
			}
			if ((choose1 == 3 && choose2 == 4) || (choose1 == 3 && hero2.Stun != 0))
			{
				printf("'%s'进行了重攻击,对'%s'造成了'%d'点伤害\n", hero1.name, hero2.name, hero1.POW * 2 - hero2.DEF);
				printf("'%s'破开了'%s'的防御\n", hero1.name, hero2.name);
				hero2.HP -= (hero1.POW * 2 - hero2.DEF);
				printf("'%s'剩余'%d'HP\n", hero2.name, hero2.HP);
				hero2.Stun += 2;
			}
		}
	}

	return hero2;
}

//硬直计数器
void Init_Hero_Stun(herodata* hero)
{
	if ((*hero).Stun >= 4)
	{
		(*hero).Stun = 0;
		printf("%s从硬直中恢复\n", (*hero).name);
	}
	if ((*hero).Stun!=0)
	{
		hero->Stun++;
	}
}

//胜利检定
void Victory_Check(herodata* hero1, herodata* hero2 ,herolist* listdata)
{
	if (hero2->HP <= 0)
	{
		printf("%s获得胜利!\n", hero1->name);
		hero1->victory++;
		hero2->lost++;
	}
	else
	{
		printf("%s获得胜利!\n", hero2->name);
		hero2->victory++;
		hero1->lost++;
	}
	listdata->list[hero1->num].victory = hero1->victory;
	listdata->list[hero2->num].victory = hero2->victory;
	listdata->list[hero1->num].lost = hero1->lost;
	listdata->list[hero2->num].lost = hero2->lost;
}

//硬直检定
void Stun_Check(herodata hero)
{
	if (hero.Stun != 0)
	{
		printf("'%s'处于硬直状态\n", hero.name);
	}
}

//追击检定
void Add_Attack(herodata hero, int* choose)
{
	if (hero.Stun != 0)
	{
		*choose = rand() % 3 + 1;
	}
}

//继续攻击检定
void Continue_Attack(int* choose, int action)
{
	if (action == 1)
	{
		*choose = 0;
	}
}